<?php

error_reporting(E_ALL);

/**
 * ConexionBD - class.ConexionBD.php
 *
 * $Id$
 *
 * This file is part of ConexionBD.
 *
 * Automatically generated on 16.12.2009, 16:13:36 with ArgoUML PHP module 
 * (last revised $Date: 2008-04-19 08:22:08 +0200 (Sat, 19 Apr 2008) $)
 *
 * @author Miguel Angel Chavez Obregon
 * @see Funcion con operativas basicas a la base de datos, cualquier metodo que se requiera hacer que no sea directo a la base de datos debera crear una clase que haga extend a esta.
 * @version 1.0
 */

if (0 > version_compare(PHP_VERSION, '5')) {
    die('This file was generated for PHP 5');
}

/* user defined includes */
// section -64--88--126-60--2cfd2a04:125047a58ba:-8000:0000000000000DDA-includes begin
// section -64--88--126-60--2cfd2a04:125047a58ba:-8000:0000000000000DDA-includes end

/* user defined constants */
// section -64--88--126-60--2cfd2a04:125047a58ba:-8000:0000000000000DDA-constants begin
// section -64--88--126-60--2cfd2a04:125047a58ba:-8000:0000000000000DDA-constants end

/**
 * Short description of class ConexionBD
 *
 * @access public
 * @author Miguel Angel Chavez Obregon
 * @see Funcion con operativas basicas a la base de datos, cualquier metodo que se requiera hacer que no sea directo a la base de datos debera crear una clase que haga extend a esta.
 * @version 1.0
 */
class ConexionBD
{
    // --- ASSOCIATIONS ---


    // --- ATTRIBUTES ---

    /**
     * Short description of attribute server
     *
     * @access public
     * @var String
     */
    public $server = null;

    /**
     * Short description of attribute usuario
     *
     * @access public
     * @var String
     */
    public $usuario = null;

    /**
     * Short description of attribute pass
     *
     * @access public
     * @var String
     */
    public $pass = null;

    /**
     * Short description of attribute base
     *
     * @access public
     * @var String
     */
    public $base = null;

    /**
     * Short description of attribute link
     *
     * @access public
     * @var String
     */
    public $link = null;

    // --- OPERATIONS ---

    /**
     * Short description of method __construct
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @param  int server
     * @param  int usuario
     * @param  int pass
     * @param  int base
     * @return void
     */
    public function __construct($server, $usuario, $pass, $base)
    {
        // section -64--88--126-60--2cfd2a04:125047a58ba:-8000:0000000000000DE7 begin
            $this->server = $server;
            $this->usuario = $usuario;
            $this->pass = $pass;
            $this->base = $base;
            $this->connect();
        // section -64--88--126-60--2cfd2a04:125047a58ba:-8000:0000000000000DE7 end
    }

    /**
     * Short description of method connect
     *
     * @access protected
     * @author firstname and lastname of author, <author@example.org>
     * @return void
     */
    protected function connect()
    {
        // section -64--88--126-60--2cfd2a04:125047a58ba:-8000:0000000000000DED begin
        $this->link = mssql_connect($this->server, $this->usuario, $this->pass)or die("ERROR DE CONEXION: ".mssql_get_last_message());
        mssql_select_db($this->base,$this->link) or die ("ERROR CON LA BASE DE DATOS: ".mssql_get_last_message());
        // section -64--88--126-60--2cfd2a04:125047a58ba:-8000:0000000000000DED end
    }

    /**
     * Short description of method desconnect
     *
     * @access protected
     * @author firstname and lastname of author, <author@example.org>
     * @return void
     */
    protected function desconnect()
    {
        // section -64--88--126-60--2cfd2a04:125047a58ba:-8000:0000000000000DEF begin
        // section -64--88--126-60--2cfd2a04:125047a58ba:-8000:0000000000000DEF end
    }

    /**
     * Short description of method ejecutaSP
     *
     * @access protected
     * @author firstname and lastname of author, <author@example.org>
     * @param  int sp
     * @param  int param
     * @return void
     */
    protected function ejecutaSP($sp, $param)
    {
        // section -64--88--126-60--2cfd2a04:125047a58ba:-8000:0000000000000DF1 begin
            $stp=mssql_init($sp,$this->link);

            mssql_bind($stp,'@param',$param,SQLVARCHAR,false,false,8000);
            
            $resultSet=mssql_execute($stp);
            $result=mssql_fetch_array($resultSet,MSSQL_ASSOC);
            mssql_free_statement($stp);
            return $result;

        // section -64--88--126-60--2cfd2a04:125047a58ba:-8000:0000000000000DF1 end
    }

    /**
     * Short description of method creaCombo
     *
     * @access protected
     * @author firstname and lastname of author, <author@example.org>
     * @param  int sp
     * @param  int name
     * @param  int onXChange
     * @param  int status
     * @param  int default
     * @param  int param
     * @return void
     */
    protected function creaCombo($sp, $name, $id, $onXChange, $status, $default, $param)
    {
        // section -64--88--126-60--2cfd2a04:125047a58ba:-8000:0000000000000DF3 begin
        if($onXChange) $onchange = "onchange='$onXChange'"; else $onchange = '';
	$result="<select $onchange name=\"$name\" id=\"$id\" class=\"datos\" $status>\n";
	$result.="<option value=''>--></option>";
       $stpro=mssql_init($sp,$this->link);
       
           mssql_bind($stpro,'@param',$param,SQLVARCHAR,false,false,3);
       
    
       $resultSet=mssql_execute($stpro);
            while ($res=mssql_fetch_array($resultSet,MSSQL_NUM)){
                if (rtrim($default) == rtrim($res[0])) {$selected="selected";} else {$selected="";}
                $result.="<option value=\"$res[0]\" $selected>$res[1]</option>\n";
            }
            mssql_free_statement($stpro);
        return $result;

        // section -64--88--126-60--2cfd2a04:125047a58ba:-8000:0000000000000DF3 end
    }

    /**
     * Short description of method recMetadato
     *
     * @access public
     * @author Edwin Mart?nez Almaz?n
     * @param  int sp
     * @param  int param
     * @return void
     * @see Funci?n que recupera el nombre de la columnas generadas por una consulta.
     * @since 16/12/2009
     * @version 1.0
     */
    public function recMetadato($sp, $param)
    {
        // section 10-16--35--34--64a6d980:1259944637a:-8000:0000000000001014 begin
        $stp=mssql_init($sp,$this->link);
        mssql_bind($stp,'@param',$param,SQLVARCHAR,false,false,8000);

        $resultSet=mssql_execute($stp);
        $num = mssql_num_fields($resultSet);

        for ($x=0;$x<$num;$x++)
            {
		$xcampo[$x] = mssql_field_name($resultSet, $x);
            }
        mssql_free_statement($stp);
        return $xcampo;
        // section 10-16--35--34--64a6d980:1259944637a:-8000:0000000000001014 end
    }

} /* end of class ConexionBD */

?>